package bTree.LeetCode;

public class 验证回文串2 {
    public boolean validPalindrome(String s) {
        int length = s.length();
        int left=0,right=length-1;
        while (left<=right){
            if(s.charAt(left)!=s.charAt(right)){
                String s1=s.substring(0,left)+s.substring(left+1,length);
                String s2=s.substring(0,right)+s.substring(right+1,length);
                return can(s1)||can(s2);
            }
            left++;
            right--;
        }
        return true;
    }

    private boolean can(String s) {
        int length = s.length();
        int left=0,right=length-1;
        while (left<=right){
            if(s.charAt(left)!=s.charAt(right)){
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
}